<!doctype html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, max-scale=1, min-scale=1,user-scalable=no">
    <meta name="_token" content="{{ csrf_token() }}"/>


    <!--引入微信js-SDK-->
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script type="text/javascript" src=" {{env('CDN_RESOURCE')}}/js/mobile/wx_config.js?v={{config('app.version')}}"></script>


    <link href="{{env('CDN_RESOURCE')}}/css/mobile/campaign/doubleEleven/mobile.css?v={{config('app.version')}}" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="https://res.wx.qq.com/open/libs/weuijs/1.1.2/weui.min.js"></script>
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css">

    {{--<script src="http://qzonestyle.gtimg.cn/open/qcloud/video/h5/h5connect.js"></script>--}}


    <script type="text/javascript" src="https://static-app.97kid.com/wx/js/zepto.min.js"></script>
    <script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/mobile/Zepto_fx_methods.js"></script>
    <script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/mobile/login.js?v={{config('app.version')}}"></script>
    <script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/AV.analytics.js"></script>

    <title>Qkids久趣英语</title>

</head>
<body>

<div class="s-header">
    <div class="logo"></div>
    <div class="apply-btn-s white-btn apply" id="top-btn" data-field="{{$campaignProduct['p_id']}}">立即开团</div>
</div>


<div class="blue-bg">
    <div class="cover">
        <div class="b">严选北美外教</div>
        <div class="m">在线授课</div>
        <div class="s">
            4-12岁适用
        </div>


        <div style="position: relative">
            <img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/family.png">

        </div>

    </div>
    <div class="white-padding"></div>
</div>

<div class="wrapper">

    <div class="section" style="padding-top:0;">


        <img class="left" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/r_left.png">
        <img class="right" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/r_right.png">

        <div class="hot-offer">
            <img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/group_buy_detail.png">

        </div>

        <div class="due-date">
            课时有效期截止至2017年12月31日
        </div>

        <div class="reg-btn apply-btn" data-field="{{$campaignProduct['p_id']}}">
            立即开团
        </div>

        <div class="notice">
            成团时间：2天 00:00:00
        </div>

    </div>

    <section id="groupBuyDetail">
        <div class="group-buy-list" id="groupBuyList">
        </div>

        <div class="group-buy-status" id="groupBuyStatus">
        </div>
    </section>


    <div class="section" style="padding:10px 0 40px 0;">
        <div class="header">活动进度</div>
        <div class="camp-step">
            <div class="item">
                <div class="group-buy-step1 icon"></div>
                <span>开团当团长</span>
            </div>
            <div class="item">
                <div class="group-buy-step2 icon"></div>
                <span>参团支付</span>
            </div>
            <div class="item">
                <div class="group-buy-step3 icon"></div>
                <span>邀请好友参团</span>
            </div>
            <div class="item">
                <div class="group-buy-step4 icon"></div>
                <span>团购完成</span>
            </div>
            <div>
                <div class="connect-line"></div>
                <div class="connect-line"></div>
                <div class="connect-line"></div>
            </div>
        </div>
    </div>

    <div class="section">
        <div class="header">活动信息</div>
        <div class="instruction">
            <div>本次双十一活动课时限量10000份，购完即止。</div>
            <div>新老用户均可开团、参团，每人仅限购买一次，重复购买需办理退费。</div>
            <div>课时适用于久趣所有课程，有效期（上课时间）自团购成功起，截止至<span class="due">2017年12月31日</span>，不可延期，逾期可按“购买单价*剩余课时”办理退费，请合理安排上课时间。（活动课时使用情况可在公众号点击"预约上课"-"新版约课"-"我的"-"课时详情"查看）
            </div>
            <div>本次活动不适用于奖学金奖励规则。</div>
            <div>更多信息可微信咨询“久趣英语服务号”。</div>
            <div>未成团系统将在3-5个工作日为您自动退款。</div>
        </div>
    </div>

    <div class="section">
        <div class="graduation-icon-c"></div>
        <div class="header">严选北美外教</div>
        <img src="{{env('CDN_RESOURCE')}}/img/mobile/teacher.png">
        <div class="statistic">
            <div class="item">
                <div class="up">1%</div>
                <div class="down">考核通过率</div>
            </div>

            <div class="item">
                <div class="up">100%</div>
                <div class="down">来自美国，加拿大</div>
            </div>

            <div class="item">
                <div class="up">95+</div>
                <div class="down">家长评分</div>
            </div>
        </div>
    </div>

    <div class="section">
        <div class="interest-icon-c"></div>
        <div class="header">趣味教学场景</div>
        <div class="sub-header">孩子到久趣的第一个转变—主动要求上课</div>
        <img src='{{env('CDN_RESOURCE')}}/img/mobile/teaching.png'>

        <div class="lesson-steps">
            <div class="item">
                <div class="photo-icon"></div>
                <div class="text">丰富动画</div>
            </div>


            <div class="item">
                <div class="game-icon"></div>
                <div class="text">游戏化</div>
            </div>


            <div class="item">
                <div class="thumbsup-icon"></div>
                <div class="text">同伴激励</div>
            </div>


        </div>
    </div>

    <div class="section">
        <div class="level-icon-c"></div>
        <div class="header">科学分级课程体系</div>
        <div class="sub-header">
            <span>基于欧洲语言共同框架（CEFR）独家研发</span>
            <span>与新课标接轨，更适合中国孩子学习</span>
        </div>

        @include('mobile.partial.courseSystem')

    </div>


    <div class="section ">
        <div class="blue-divider"></div>
        <div class="header">特惠价格，即刻报名</div>
        <div class="sub-header">180天无条件退款，报名后即可上课</div>

        <div class="lesson-plan">

            {{--@foreach($products as $product)--}}
            {{----}}
            {{--<div class="detail zoom-out" data-field="{{$product['p_id']}}">--}}

            {{--<div class="fee">--}}
            {{--<span class="up">--}}
            {{--¥ <span class="money">{{$product['total']}}</span>--}}
            {{--</span>--}}
            {{--<span class="down">--}}
            {{--/{{$product['duration']}} 课时--}}
            {{--</span>--}}
            {{--</div>--}}

            {{--<div class="schedule">--}}
            {{--<div><span>{{$product['refundDate']}}</span></div>--}}
            {{--<div><span>{{$product['suggestion']}}</span></div>--}}
            {{--<div><span>{{$product['extra']}}</span></div>--}}
            {{--<div class="reg-btn buy-btn">购买</div>--}}
            {{--</div>--}}

            {{--</div>--}}
            {{----}}
            {{--@endforeach--}}


            <div class="detail zoom-out">

                <div class="fee">
                        <span class="up">
                            ¥ <span class="money">100</span>
                        </span>
                    <span class="down">
                            /4 课时
                        </span>
                </div>

                <div class="schedule">
                    <div><span>自购买起，一个月内有效</span></div>
                    <div><span>建议4-6节课/周</span></div>
                    <div><span>本期招生仅限前500</span></div>
                    <div class="reg-btn buy-btn" data-field="4">购买</div>
                </div>

            </div>

            <div class=" detail zoom-in">

                <div class="fee">
                        <span class="up">
                            ¥ <span class="money">3200</span>
                        </span>
                    <span class="down">
                            /80 课时
                        </span>
                </div>

                <div class="schedule">
                    <div><span>自购买起，课时一年内有效</span></div>
                    <div><span>建议4-6节课/周</span></div>
                    @if($largeLimit['day'] > 0)
                        <div class="reg-btn buy-btn disable" data-field="6">待开放</div>
                    @else
                        <div class="reg-btn buy-btn" data-field="6">购买</div>
                    @endif
                </div>

            </div>


            <div class=" detail zoom-out">

                <div class="fee">
                        <span class="up">
                            ¥ <span class="money">1780</span>
                        </span>
                    <span class="down">
                            /40 课时
                        </span>
                </div>

                <div class="schedule">
                    <div><span>自购买起，课时半年内有效</span></div>
                    <div><span>建议4-6节课/周</span></div>
                    @if($largeLimit['day'] > 0)
                        <div class="reg-btn buy-btn disable" data-field="5">待开放</div>
                    @else
                        <div class="reg-btn buy-btn" data-field="5">购买</div>
                    @endif
                </div>

            </div>


        </div>
    </div>


    <div class="section">

        <div class="blue-divider"></div>
        <div class="header">简单<span>3</span>步，立即上课</div>

        <div class="lesson-steps" style="margin-top:10px;">
            <div class="item">
                <div class="ok-icon"></div>
                <span>购买课程</span>
            </div>

            <div class="item">
                <div class="chat-icon"></div>
                <span>微信约课</span>
            </div>

            <div class="item">
                <div class="tv-icon"></div>
                <span>进入教室</span>
            </div>
        </div>

        <div class="class-type">
            <div class="c-header">精品4、6人班，每节课30分钟</div>
            <div class="type">
                <div>
                    <span>6</span>人班&nbsp<span>1</span>课时/节
                </div>

                <div><span>4</span>人班&nbsp<span>1.5</span>课时/节</div>

            </div>
        </div>
    </div>

    <div class="section">
        <div class="blue-divider"></div>
        <div class="header">家长说</div>
        <div class="review" id="review">
            <div class="left-r item ">
                <img src="{{env('CDN_RESOURCE')}}/img/mobile/avatar1.png"/>
                <div class="text">喜欢久趣，我们家一天一节课，孩子主动要求的。</div>

                <div class="review-who">
                    <span>Mike 的家长</span>
                </div>
            </div>

            <div class="right-r item ">

                <div class="text">全程课小孩自己上完了，完全没让我帮忙。</div>
                <img src="{{env('CDN_RESOURCE')}}/img/mobile/avatar2.png"/>

                <div class="review-who">
                    <span>Lorna 的家长</span>
                </div>
            </div>

            <div class="left-r item ">
                <img src="{{env('CDN_RESOURCE')}}/img/mobile/avatar3.png"/>
                <div class="text">现在上课已经成为了小朋友期盼的一件事，真不错！</div>

                <div class="review-who">
                    <span>Steve 的家长</span>
                </div>
            </div>

            <div class="right-r item ">

                <div class="text">老师的语音语调都很好听，很地道。</div>
                <img src="{{env('CDN_RESOURCE')}}/img/mobile/avatar4.png"/>

                <div class="review-who">
                    <span>Vincent 的家长</span>
                </div>
            </div>

            <div class="left-r item ">
                <img src="{{env('CDN_RESOURCE')}}/img/mobile/avatar5.png"/>
                <div class="text">孩子对语言很敏感，我希望他从小就接触纯正的表达。</div>

                <div class="review-who">
                    <span>Alina 的家长</span>
                </div>
            </div>

        </div>

    </div>
</div>

{{--@include('mobile.partial.loginAndRegister')--}}

<div class="footer">

    <div class="icon-links">
        <div class="logo-blue"></div>
    </div>

    <div class="email">
        <div class="header">企业邮箱</div>
        <div class="text">service@qkids.cn</div>
    </div>

    {{--<div class="qr-code">
        <img src="{{env('CDN_RESOURCE')}}/img/mobile/qrcode.png"/>
        <span>微信公众号</span>
        <span>久趣英语服务号</span>
    </div>--}}


    <div class="copy-right">
        <span>Copyright @2017-2018 Qkids All Rights Reserved</span>
        <span>闽ICP备12021838号-3</span>
    </div>

</div>

<div class="video-mask" id="videoMask">
    <div class="close-icon icon" id="closeVideo"></div>
    <div id="videoContainer" class="video">
    </div>
</div>

<div class="buy-restrict">
    <div class="info">
        您已经购买过 ¥100／4课时，建议您购买长期课时
    </div>

    <a href="/wx/vip">
        <div class="small-btn confirm-btn">前往购买</div>
    </a>

</div>


<div class="group-status" id="groupStatus">
    <div class="explanation">

        <div class="top-banner">
            <img class="monkey sad-monkey"
                 src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/sad_monkey.png">
            <img class="monkey happy-monkey"
                 src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/happy_monkey.png">
            <img class="monkey normal-monkey"
                 src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/normal_monkey.png">
            <img class="left" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/b_left.png">
            <img class="right" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/doubleEleven/b_right.png">
        </div>

        <div class="group-detail">
            <div class="title"></div>
            <div class="text"></div>
        </div>

        {{--<div class="detail group-full">--}}
        {{--<div class="title">已满员，请重新开团</div>--}}
        {{--<div class="text">亲爱的家长，该团已满员，请您重新开团参加双十一团购活动吧。</div>--}}
        {{--</div>--}}

        {{--<div class="detail group-overdue">--}}
        {{--<div class="title">活动已结束</div>--}}
        {{--<div class="text">亲爱的家长，您未在规定时间成团，系统将在3个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。</div>--}}
        {{--</div>--}}

        {{--<div class="detail doubleEleven-group-done">--}}
        {{--<div class="title">活动已结束</div>--}}
        {{--<div class="text">亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。</div>--}}
        {{--</div>--}}

        {{--<div class="detail group-overdue-active">--}}
        {{--<div class="title">很遗憾</div>--}}
        {{--<div class="text">亲爱的家长，您未在规定时间成团，系统将在3个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加双十一活动吧。</div>--}}
        {{--</div>--}}

        {{--<div class="detail group-done">--}}
        {{--<div class="title">请重新开团</div>--}}
        {{--<div class="text">亲爱的家长，该团已结束，请您重新开团参加双十一团购活动吧。</div>--}}
        {{--</div>--}}


        <div class="reg-btn ok-btn" id="okBtn">确定</div>
    </div>
</div>

<div class="buy-restrict">
    <div class="info">
        您已经购买过 ¥100／4课时，建议您购买长期课时
    </div>

    <a href="/wx/vip">
        <div class="small-btn confirm-btn">前往购买</div>
    </a>

</div>


<div class="share-mask">
    <div class="share-arrow"></div>
</div>

<div id="alertBox" class="alert-box"></div>

@include('template.ga')
</body>
</html>


<script type="text/javascript">

    (function ($) {

        $(function () {

            var currentLevel = 1;
            var previousLevel = 1;
            var offset = 5;
            var isInWechat = false;
            var userAgent = navigator.userAgent;
            //var userAgent = "Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X) AppleWebKit/534.46(KHTML,like Geocko) Mobile/9B206 MicroMessenger/5.0";
            var wechatInfo = userAgent.match(/MicroMessenger\/([\d\.]+)/i);
            if (wechatInfo) {
                isInWechat = true;
            }

            // 最简的示例代码，请换成自己的 appId 和 appKey
            var appId = 'antYy9lOFi5mkU9QKjtYmRLM-gzGzoHsz';
            var appKey = 'jqyWxLyobpsmdwsJddJlDheb';

            // 实例化统计分析功能（注意：实例化后，SDK 会自动开始统计 PV、UV、停留页面时长等信息）
            var analytics = AV.analytics({
                // 设置 AppId
                appId: appId,
                // 设置 AppKey
                appKey: appKey,
                // 你当前应用的渠道或者你想指定的渠道（自定义）
                channel: wechatInfo ? 'weixin' : ''
            });

            //  选择课程分级
            $('.level-slide-list span').click(function () {

                var nav = $(this);
                previousLevel = currentLevel;
                currentLevel = $(this).index() + 1;


                nav.addClass('active-level').siblings('span').removeClass('active-level');
                if (offset === currentLevel && (currentLevel !== 12 )) {

                    $('#levelSlideList').animate(
                        {
                            left: -$('#firstLevel').width() * (offset - 1 )
                        },
                        {
                            duration: 250, complete: function () {
                            $('#unavCursor').animate({
                                left: nav.offset().left - 0.05 * window.screen.width
                            }, 250);
                        }
                        });

                    offset = offset + ( 5 - 1 );

                } else if ((offset - 4) === currentLevel && (currentLevel !== 1 )) {

                    $('#levelSlideList').animate(
                        {
                            left: -$('#firstLevel').width() * (offset - 9 )
                        },
                        {
                            duration: 250, complete: function () {
                            $('#unavCursor').animate({
                                left: nav.offset().left - 0.05 * window.screen.width
                            }, 250);
                        }
                        });

                    offset = offset - ( 5 - 1 );

                } else {
                    $('#unavCursor').animate({
                        left: nav.offset().left - 0.05 * window.screen.width
                    }, 250, function () {
                    })
                }
                $('.level-info .level-item').eq(currentLevel - 1).addClass('active-level-item').siblings('.level-item').removeClass('active-level-item');

            });


            var totalPlans = 3;
            var clickItem = null;
            $('.lesson-plan .detail').on('click', function () {
                $(this).addClass('zoom-in').removeClass('zoom-out');
                $(this).siblings('div').each(function () {
                    if ($(this).hasClass('zoom-in')) {
                        $(this).removeClass('zoom-in').addClass('zoom-out');
                    }
                })

                if ($(this).index() === ( totalPlans - 1 )) {
                    clickItem = $('.lesson-plan .detail').eq(0);
                    $('.lesson-plan .detail').eq(0).remove();
                    $('.lesson-plan').append(clickItem);
                }

                if ($(this).index() === 0) {
                    clickItem = $('.lesson-plan .detail').eq(totalPlans - 1);
                    $('.lesson-plan .detail').eq(totalPlans - 1).remove();
                    $('.lesson-plan').prepend(clickItem);
                }
            });


            var timeout;
            $(document).bind("scroll", function () {

                clearTimeout(timeout);
                timeout = setTimeout(function () {

                    var reviewList = $('#review');
                    if ($(window).scrollTop() > reviewList.offset().top - 600) {

                        if (reviewList.css('visibility') === 'hidden') {
                            reviewList.css('visibility', 'visible');
                            reviewList.find('.item').each(function () {
                                $(this).addClass('fade-animate');
                            })
                        }
                    }
                }, 10);
            });


            // 微信活动逻辑
            {
                var configOption = {
                    timestamp: '{{$signature['timestamp']}}',
                    nonceStr: '{{$signature['nonceStr']}}',
                    signature: '{{$signature['signature']}}',
                    jsApiList: ['onMenuShareTimeline', 'chooseWXPay', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone']
                };
                var wxconfig = new WxConfig(configOption, 'doubleeleven');
                var account = new Account();
                var groupBuyStatus = 0;
                var campaignEnd = 1512057599;
                var creator = 0;
                var gid = '';

                function getGId() {
                  var gid = '{{$gid}}';
                  if (!gid) {
                    var path = localStorage.getItem('QKidsPathname');
                    function getMatched(name, string) {
                      if (string) {
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                        var len = string.indexOf('?') == 0 ? 1 : 0;
                        var r = string.substr(len).match(reg);
                        if (r != null) return unescape(r[2]);
                      }
                      return null;
                    }
                    var localGid = getMatched('gid', decodeURIComponent(path));
                    if (localGid) gid = localGid;
                  }
                  return gid;
                }
                account.forceLogin = false;
                account.getUserInfo(function (err, userInfo) {
                    gid = getGId();
                    if (gid || !err) {
                      getGroupBuyInfo(gid);
                    }
                });


                //提交订单
                $('.buy-btn').click(function() {
                  submitOrder($(this).attr('data-field'));
                })
                $('.apply-btn, .apply-btn-s').click(function () {

                    if( groupBuyStatus === 3 && groupBuyStatus === 7 ){
                        window.location.href = '/wx';
                    } else if (groupBuyStatus === 2 || groupBuyStatus === 1){
                        $('.share-mask').fadeIn();
                    } else {
                        submitOrder($(this).attr('data-field'));
                    }
                });

                //关闭提示窗口
                $('#okBtn').click(function () {
                    $('#groupStatus').fadeOut();
                })

                //关闭分享提示
                $('.share-mask').click(function(){
                    $(this).fadeOut();
                })

                function submitOrder(pId) {
                    var campUrl = window.location.protocol + '//' + window.location.host + '/wx/doubleeleven';
                    var campPara = {
                      gid: getGId(),
                    };
                        account.forceLogin = true;
                    //提交订单久趣后台
                    account.getUserInfo(function (userInfoError, userInforesult) {

                        if (userInfoError) {
                            $.toastAlert(userInfoError.message);
                        } else {
                            if (isInWechat) {
                                //配置微信分享接口
                                wxconfig.activeShare(userInforesult.shareFlag, campPara);
                            }
                            account.ajax({
                                type: 'POST',
                                path: '/s/bills',
                                data: {
                                    productId: pId,
                                    payChannel: isInWechat ? 'weixin' : 'alipay',
                                    returnUrl: window.location.protocol + '//' + window.location.host + '/wx/verifypayment/' + pId,
                                    tradeType: 'JSAPI',
                                    openId: window.localStorage.getItem(account.openId),
                                    groupBuyingId: groupBuyStatus === 5 ? '' : encodeURIComponent(decodeURIComponent(campPara['gid']))
                                },
                                success: function (data) {
                                    //唤起微信支付
                                    if (data.status !== 'error') {
                                        analytics.send({
                                            // 事件名称
                                            event: 'doubleeleven-bill-success',
                                            // 事件属性，任意数据
                                            attr: {
                                                productId: pId,
                                                billId: data.bill_id,
                                                isInWechat: isInWechat
                                            }
                                        });
                                        if (isInWechat) {
                                          var jsApiParameters = JSON.parse(data.jsApiParameters);
                                          jsApiParameters.success = function() {
                                            analytics.send({
                                              // 事件名称
                                              event: 'doubleeleven-pay-success',
                                              // 事件属性，任意数据
                                              attr: {
                                                productId: pId,
                                                billId: data.bill_id,
                                                isInWechat: isInWechat
                                              }
                                            });
                                          };
                                          jsApiParameters.fail = function() {
                                            analytics.send({
                                              // 事件名称
                                              event: 'doubleeleven-pay-fail',
                                              // 事件属性，任意数据
                                              attr: {
                                                productId: pId,
                                                billId: data.bill_id,
                                                isInWechat: isInWechat
                                              }
                                            });
                                          }
                                          wxconfig.pay(data.bill_id, pId, jsApiParameters, campUrl);

                                        } else {
                                            window.location.href = data.url;
                                        }
                                    } else {
                                        analytics.send({
                                            // 事件名称
                                            event: 'doubleeleven-bill-fail',
                                            // 事件属性，任意数据
                                            attr: {
                                                productId: pId,
                                                billId: data.bill_id,
                                                isInWechat: isInWechat
                                            }
                                        });
                                        $.toastAlert('下单失败，请重试');
                                    }
                                },
                                error: function (err) {
                                    if (err.code === 'product.rejected.by.bought.products') {
                                        $.toastAlert('您已经参加活动');
                                        getGroupBuyInfo();

                                    }

                                }
                            });

                        }

                    });
                }

                {{--function getGroupByResult() {--}}
                {{--account.ajax({--}}
                {{--type: 'POST',--}}
                {{--path: '/s/groupbuy',--}}
                {{--data: {--}}
                {{--groupBuyingId: '{{$gid}}',--}}
                {{--},--}}
                {{--success: function (data) {--}}
                {{--if (data.status !== 'error') {--}}
                {{--setGroupBuyCountDown(data.endAt);--}}
                {{--getGroupBuyerList(data.buyers);--}}

                {{--} else {--}}
                {{--//$.toastAlert('下单失败，请重试');--}}
                {{--}--}}
                {{--},--}}
                {{--error: function (err) {--}}
                {{--//                        $.toastAlert(err.message, 2);--}}
                {{--}--}}
                {{--});--}}
                {{--}--}}

                function getGroupBuyInfo(gid) {

                    //已经登陆
                    if (!gid) {
                        account.ajax({
                            type: 'POST',
                            path: '/s/products/1003/buying',

                            success: function (result) {
                                //已经开团
                                creator = result.creatorId;
                                setGroupBuyStatus(result, true);
                                getGroupBuyerList(result.buyers.toString());
                                resetShareDetail(result.id);


                            },
                            error: function (err) {
                                setGroupBuyStatus(err, false);
                            }
                        })
                    } else {
                        account.ajax({
                            auth: false,
                            type: 'POST',
                            path: '/s/products/1003/buying',
                            data: {groupBuyingId: encodeURIComponent(gid)},//'fsxz2CTal9g%3D'},
                            success: function (result) {
                                //已经开团
                                creator = result.creatorId;
                                setGroupBuyStatus(result, true);
                                getGroupBuyerList(result.buyers.toString());
                                resetShareDetail(result.id);
                            },
                            error: function (err) {
                                setGroupBuyStatus(err, false);
                            }
                        })
                    }
                }


                function getGroupBuyerList(buyers) {
                    account.ajax({
                        auth: false,
                        type: 'GET',
                        path: '/s/students/socials',
                        data: {ids: buyers},
                        success: function (result) {
                            showGroupBuyerList(result);
                        },
                        error: function (err) {
                            $.toastAlert(err.message, 2);
                        }
                    });
                }

                function showGroupBuyerList(wechatInfoList) {


                    var referralListHtml = '';
                    var sortedList = [];


                    if(creator !== 0) {
                        var captain;
                        var currentBuyer;
                        var currentBuyerId = 0;
                        if(JSON.parse(window.localStorage.getItem(account.userInfoKey)) !== null) {
                            currentBuyerId = JSON.parse(window.localStorage.getItem(account.userInfoKey)).id;
                        }


                        for (var k = 0; k < wechatInfoList.length; k++) {
                            if((wechatInfoList[k].id) === creator) {
                                captain = wechatInfoList[k];
                            } else if (wechatInfoList[k].id === currentBuyerId) {
                              currentBuyer = wechatInfoList[k];
                            } else  {
                              sortedList.push(wechatInfoList[k]);
                            }
                        }

                      if (currentBuyerId !== creator && currentBuyer) {
                        sortedList.unshift(currentBuyer);
                      }

                        if (captain) {
                          sortedList.unshift(captain);
                        }
                    }

                    for (var i = 0; i < Math.min(4, sortedList.length); i++) {
                        referralListHtml += '<div class="avatar">' +
                            '<img src="' + getAvatar(sortedList[i].avatar) + '">' +
                            '<span>'+sortedList[i].nickname+'</span>' +
                            '</div>';
                    }

                    $('#groupBuyList').empty().append(referralListHtml);

                }

                function getAvatar(avatar) {
                    if(!avatar) {
                        return '{{env('CDN_RESOURCE')}}'+'/img/mobile/campaign/doubleEleven/pic_avatar_boy.png';
                    }
                    return avatar;
                }

                var starCount = null;
                function setGroupBuyCountDown(status, endAt) {

                    if (starCount) clearInterval(starCount);
                    if (status == 0) {
                      starCount = setInterval(function () {

                      var timestamp = Date.parse(new Date());
                      if (timestamp >= endAt) {
                            // 团购已经结束
                            $('.notice').text('该团购已经到期!');
                            clearInterval(starCount);

                          } else if (timestamp < endAt) {
                            var timeDiff = endAt - timestamp;
                            var day = Math.floor(timeDiff / 1000 / 60 / 60 / 24);
                            var hour = Math.floor(timeDiff / 1000 / 60 / 60 % 24);
                            var min = Math.floor(timeDiff / 1000 / 60 % 60);
                            var sec = Math.floor(timeDiff / 1000 % 60);

                            if (hour < 10) {
                              hour = "0" + hour;
                            }
                            if (min < 10) {
                              min = "0" + min;
                            }
                            if (sec < 10) {
                              sec = "0" + sec;
                            }
                            var countDownTime = hour + ":" + min + ":" + sec;
                            $('.notice').text('成团时间: ' + day + '天' + countDownTime);
                          }
                        }, 1000);

                    }  else if (status == 1) {
                      $('.notice').text('已成团');
                    } else {
                      $('.notice').text('已过期');
                    }

                }

                //已登陆

                //setGroupBuyStatus({}, true);
                function setGroupBuyStatus(gpDetail, status) {
                  if (!gpDetail || !gpDetail.id) return;

                    //  status: 1->已报名 2->未报名

//                alert(groupBuyTimeStatus(gpDetail.endAt) + '-'  + campaignTimeStatus());

                  var currentBuyerId = 0;
                  if(JSON.parse(window.localStorage.getItem(account.userInfoKey)) !== null) {
                    currentBuyerId = JSON.parse(window.localStorage.getItem(account.userInfoKey)).id;
                  }

                  var inGroup = gpDetail.buyers && gpDetail.buyers.indexOf(currentBuyerId) >= 0;

                  var cStatus = campaignTimeStatus();

                  var endAt1 = new Date().getTime() / 1000 + 1000;
                  var endAt2 = new Date().getTime() / 1000 - 1000;

                  //status = true;
                  //cStatus = true;
                  //inGroup = true;

                  // 组团中
                  //gpDetail = { id: 1, status: 2, buyerCount: 2, endAt: endAt1, buyers: [9]};
                  // 团成功
                  //gpDetail = { id: 1, status: 1, buyerCount: 4, endAt: endAt2, buyers: [7,8,9,27]};
                  // 团过期
                  //gpDetail = { id: 1, status: 2, buyerCount: 4, endAt: endAt2, buyers: [9]};

                  setGroupBuyCountDown(gpDetail.status, gpDetail.endAt * 1000);
                  if (gpDetail.status === 0) {
                    if (inGroup) displayGroupBuyStatus(2, gpDetail.buyerCount);
                    else displayGroupBuyStatus(8, gpDetail.buyerCount);
                  } else if (gpDetail.status === 1) {
                    if (inGroup) displayGroupBuyStatus(1);
                    else {
                      if (cStatus) displayGroupBuyStatus(5);
                      else displayGroupBuyStatus(7);
                    }
                  } else {
                    if (cStatus) {
                      if (inGroup) displayGroupBuyStatus(4);
                      else displayGroupBuyStatus(6)
                    } else {
                      if (inGroup) displayGroupBuyStatus(3);
                      else displayGroupBuyStatus(7);
                    }
                  }

                }

                function groupBuyTimeStatus(groupBuyEnd) {
                    return (new Date).getTime()/1000 <= groupBuyEnd;
                }

                function campaignTimeStatus() {
                    return (new Date).getTime()/1000 <= campaignEnd ;
                }

                function displayGroupBuyStatus(status, buyerCounter) {
                  $('.camp-step .icon').removeClass('active');
                    if (status === 1) {
                        $('.group-buy-step4').addClass('active');
                        //happy monkey
                        // 团购成功( 已报名 已成团 活动时间未到期 )
                        //亲爱的家长，您已成功购入双十一活动课时（￥148/8课时），北美外教给您准备了有趣的课程，快去预约上课吧！
                        $('.apply-btn').text('团购成功，分享给好友');
                        $('.group-buy-status').text('当前团购成功');
                        $('.happy-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('团购成功');
                        $('.group-detail .text').text('亲爱的家长，您已成功购入双十一活动课时（￥148/8课时），北美外教给您准备了有趣的课程，快去预约上课吧！');
                        $('#top-btn').text('立即分享');
                        $('#groupStatus').show();
                        groupBuyStatus =1;

                    } else if (status === 2) {
                        //尚未成团 (已报名 团没有满 团购时间未到期 活动时间还没到期  )
                        $('.apply-btn').text('邀请好友参团');
                        $('.group-buy-status').text(' 还差' + (4 - buyerCounter) + '人即可成团，邀请更多好友共享');
                        $('#top-btn').text('立即邀请');
                        groupBuyStatus =2;
                      $('.group-buy-step3').addClass('active');

                    } else if (status === 3) {
                        //normal monkey
                        //活动已结束( 已报名 团没有满 团购时间到期 活动时间已到期)
                        //亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。
                        $('.apply-btn').text('查看其他优惠');
                        $('.group-buy-status').text('双11活动已结束');
                        $('.normal-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('活动已结束');
                        $('.group-detail .text').text('亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3-5个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。');
                        $('#top-btn').hide();
                        $('#groupStatus').show();
                        groupBuyStatus =3;

                    } else if (status === 4) {
                      $('.group-buy-step1').addClass('active');
                        //sad monkey
                        //很遗憾( 已报名 团没有满 团购时间到期 活动时间未到期)
                        //亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加双十一活动吧。
                        $('.apply-btn').text('重新开团');
                        $('.group-buy-status').text('未能组团成功，请重新开团');
                        $('.sad-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('很遗憾');
                        $('.group-detail .text').text('亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3-5个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加双十一活动吧。');
                         $('#top-btn').text('重新开团');
                        $('#groupStatus').show();
                        groupBuyStatus =4;

                    } else if (status === 5) {
                      $('.group-buy-step4').addClass('active');
                        //normal monkey
                        // 该团已满，重新开团( 未报名 团已满 活动时间未到期 )
                        //亲爱的家长，该团已满员，请您重新开团参加双十一团购活动吧。
                        $('.apply-btn').text('重新开团');
                        $('.group-buy-status').text('该团已满员，请重新开团');
                        $('.normal-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('该团已满，重新开团');
                        $('.group-detail .text').text('亲爱的家长，该团已满员，请您重新开团参加双十一团购活动吧。');
                        $('#groupStatus').show();
                        $('#top-btn').text('重新开团');
                        groupBuyStatus =5;

                    } else if (status === 6) {
                        //sad monkey
                        //请重新开团(  未报名 团没有满 团购时间已经到期 活动时间未到期)
                        //亲爱的家长，该团已结束，请您重新开团参加双十一团购活动吧。
                        $('.apply-btn').text('重新开团');
                        $('.group-buy-status').text('该团团购时间结束，请重新开团');
                        $('.sad-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('请重新开团');
                        $('.group-detail .text').text('亲爱的家长，该团团购时间结束，请您重新开团参加双十一团购活动吧。');
                        $('#groupStatus').show();
                        $('#top-btn').text('重新开团');
                        groupBuyStatus =6;
                      $('.group-buy-step1').addClass('active');

                    } else if (status === 7) {
                        //normal monkey
                        //活动已结束( 未报名 活动时间到期 )
                        //亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。
                        $('.apply-btn').text('查看其他优惠');
                        $('.group-buy-status').text('活动已经结束');
                        $('.normal-monkey').show().siblings('.monkey').hide();
                        $('.group-detail .title').text('活动已结束');
                        $('.group-detail .text').text('亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。');
                        $('#groupStatus').show();
                      $('#top-btn').hide();
                        groupBuyStatus =7;
                    } else if (status === 8) {
                        //参加活动( 未报名 团购活动没有满 活动时间未到期 )
                        $('.apply-btn').text('立即参团');
                        $('.group-buy-status').text(' 还差' + (4 - buyerCounter) + '人即可成团，邀请更多好友共享');
                        $('#top-btn').text('立即参团');
                        groupBuyStatus = 8;
                      $('.group-buy-step2').addClass('active');
                    } else if (status === 9) {
                        //参加活动( 未报名 团购活动没有满 团购时间到期 活动时间未到期 )
                        $('.apply-btn').text('重新开团');
                        $('.group-buy-status').text('该团已结束，请重新开团');
                      $('#top-btn').text('重新开团');
                        groupBuyStatus =9;
                    }
                }

                function resetShareDetail(gid) {
                    var campPara = [];
                    campPara['gid'] = gid;
                    account.getUserInfo(function (err, result) {
                        if (!err && isInWechat) {
                            //配置微信分享接口
                            wxconfig.activeShare(result.shareFlag, campPara);
                        }
                    });

                }

            }
        })

    })(window.Zepto);


</script>

